package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 分类分页查询
     * @param name
     * @param type
     * @return
     */
    List<Category> queryByPage(String name, Integer type);

    /**
     * 修改
     * @param category
     */
    @AutoFill(OperationType.UPDATE)
    void update(Category category);

    /**
     * 插入
     * @param category
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into category (type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "values (#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser});")
    void insert(Category category);

    /**
     * 删除
     * @param id
     */
    @Delete("delete from category where id = #{id};")
    void deleteById(Long id);

    /**
     * 根据类型查询
     * @param type
     * @return
     */
    List<Category> queryByType(Integer type);

    /**
     * 根据id查询
     * @param categoryId
     * @return
     */
    @Select("select * from category where id = #{categoryId};")
    Category queryById(Long categoryId);
}
